@extends('Admin.layouts.application')
@section('css')
    <link rel="stylesheet" href="/assets/xSystem/vendor/daterangepicker/daterangepicker.css">

@endsection
@section('content')
    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">APP菜单管理</strong> /
                    <small>Service classification</small>
                </div>
            </div>

            <hr>
            @include('Admin.layouts._flash')
            <div class="am-g" style="height: 37px;">
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <a type="button" class="am-btn am-btn-default" href="{{route('category.create')}}">
                                <span class="am-icon-plus"></span> 新增二级分类
                            </a>
                            <button type="button" class="am-btn am-btn-success" id="show_all"
                                    href="{{route('category.create')}}">
                                <span class="am-icon-arrows-alt"></span> 展开所有
                            </button>
                        </div>
                    </div>
                </div>
            </div>
            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">

                        <table class="am-table am-table-striped am-table-hover table-main">
                            <thead>
                            <tr>
                                <th class="table-id">编号</th>
                                <th class="table-title">一级菜单</th>
                                <th class="table-category">二级菜单</th>
                                <th class="table-brand">是否显示</th>
                                <th class="table-price">排序</th>
                                <th class="am-hide-sm-only">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($categories as $category)
                                <tr data-id="{{$category->id}}" id="row_{{$category->id}}" class="xParent am-active">
                                    <td>{{$category->id}}</td>

                                    <td>
                                        {{ indent_category($category->count) }}
                                        {{$category->name}}
                                    </td>

                                    <td>
                                        {!! show_category_hotelreferral($category) !!}
                                    </td>
                                    @if($category->parent_id !=0)
                                        <td class="am-hide-sm-only">
                                            {!! is_something('is_show', $category) !!}
                                        </td>
                                        @else
                                        <td class="am-hide-sm-only">

                                        </td>
                                    @endif
                                    <td class="am-hide-sm-only">
                                        <input  type="text" name="sort_order" class="am-input-sm"
                                                value="{{$category->sort_order}}">
                                    </td>


                                    <td>
                                        <div class="am-btn-toolbar">
                                            <div class="am-btn-group am-btn-group-xs">
                                                <a class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                   href="{{route('category.edit', $category->id)}}">
                                                    <span class="am-icon-pencil-square-o"></span> 编辑
                                                </a>
                                                @if($category->parent_id !=0)
                                                <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                                   href="{{route('category.destroy', $category->id)}}"
                                                   data-method="delete"
                                                   data-token="{{csrf_token()}}" data-confirm="确认删除吗?">
                                                    <span class="am-icon-trash-o"></span> 删除
                                                </a>
                                                @endif
                                            </div>
                                        </div>
                                    </td>
                                </tr>
                                @foreach ($category->children as $c)

                                    <tr data-id="{{$c->id}}" class="xChildren child_row_{{$category->id}}" style="display:table-row;">
                                        <td>{{$c->id}}</td>

                                        <td>
                                            {{ indent_category(2) }}
                                            {{$c->name}}
                                        </td>

                                        <td>
                                            {!! show_category_hotelreferral($c) !!}
                                        </td>
                                        @if($c->name !="留言信息" && $c->name !="客房点餐" && $c->name !="在线退房")
                                            <td class="am-hide-sm-only">
                                                {!! is_something('is_show', $c) !!}
                                            </td>
                                            @else
                                            <td class="am-hide-sm-only">

                                            </td>


                                        @endif

                                            <td class="am-hide-sm-only">
                                                <input type="text" name="sort_order" class="am-input-sm"
                                                       value="{{$c->sort_order}}">
                                            </td>


                                        <td>
                                            <div class="am-btn-toolbar">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    @if($c->name !="留言信息" && $c->name !="客房点餐" && $c->name !="在线退房")
                                                    <a class="am-btn am-btn-default am-btn-xs am-text-secondary"
                                                       href="{{route('category.edit', $c->id)}}">
                                                        <span class="am-icon-pencil-square-o"></span> 编辑
                                                    </a>

                                                        <a class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"
                                                           href="{{route('category.destroy', $c->id)}}"
                                                           data-method="delete"
                                                           data-token="{{csrf_token()}}" data-confirm="确认删除吗?">
                                                            <span class="am-icon-trash-o"></span> 删除
                                                        </a>
                                                    @endif
                                                </div>
                                            </div>
                                        </td>
                                    </tr>
                                @endforeach
                            @endforeach
                            </tbody>
                        </table>
                    </form>
                </div>
            </div>
        </div>
        @include('Admin.layouts._footer')

    </div>
@endsection

@section('js')

    <script src="/assets/xSystem/vendor/daterangepicker/moment.js"></script>
    <script src="/assets/xSystem/vendor/moment/locale/zh-cn.js"></script>
    <script src="/assets/xSystem/vendor/daterangepicker/daterangepicker.js"></script>

    <script src="/assets/xSystem/js/daterange_config.js"></script>
    <script>
        $(function () {
            //是否...
            $(".is_something").click(function () {
                var _this = $(this);
                var data = {
                    id: _this.parents("tr").data('id'),
                    attr: _this.data('attr')
                }
                console.log(data);
                $.ajax({
                    type: "PATCH",
                    url: "/category/is_something",
                    data: data,
                    success: function () {
                        _this.toggleClass('am-icon-close am-icon-check');
                    }
                });
            });

            //排序
            $("input[name='sort_order']").change(function () {
                var data = {
                    sort_order: $(this).val(),
                    id: $(this).parents("tr").data('id')
                };
                console.log(data);
                $.ajax({
                    type: "PATCH",
                    url: "/category/sort_order",
                    data: data,
                });
            });
            //展开与折叠表格
            $("tr.xParent").dblclick(function () {
                $(this).toggleClass('am-active');
                $(".child_" + this.id).toggle();
            });

            $("#show_all").click(function () {
                $("tr.xParent").toggleClass('am-active');
                $("tr.xChildren").toggle();
            });
        });
    </script>


    <script type="text/javascript">
        function fresh() {
            var d = "2016-09-02 09:41:59";
            var endtime = new Date(d);
            var nowtime = new Date();
            var leftsecond = parseInt((endtime.getTime() - nowtime.getTime()) / 1000);
            d = parseInt(leftsecond / 3600 / 24);
            h = parseInt((leftsecond / 3600) % 24);
            m = parseInt((leftsecond / 60) % 60);
            s = parseInt(leftsecond % 60);
            var td = d * 24 + h;
            console.log(h);
            $("#emD").html(d+'天');
            $("#emH").html(h+'时');
            $("#emM").html(m+'分');
            $("#emS").html(s+'秒');
            if (leftsecond <= 0) {
                $("#emH").html("00"+'时');
                $("#emM").html("00"+'分');
                $("#emS").html("00"+'秒');
                clearInterval(sh);
            }
        }
        fresh();
        var sh;
        sh = setInterval(fresh, 1000);
    </script>


@endsection





